import $ from 'jquery';
global.$ = global.jQuery = $;
import { mdContent } from "./../glob";
import "social-share.js/dist/css/share.min.css";
require("social-share.js/dist/js/social-share.min");

(function ($) {
    var markdown = $("#preview").html();
    if(markdown){
        mdContent($, markdown, "preview", "outline");
    }

    $("#fav").on("click", function () {
        var chref = $(this).attr("href");
        var that=$(this);
        var favNum = $("#favNum").text();
        favNum = parseInt(favNum);
        $.getJSON(chref, {}, function (responseText) {
                var nofavicon = '<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-star" width="24" height="24" viewbox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> \
                                <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> \
                                <path d="M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z"></path> \
                                </svg>';
                var favicon = '<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-star-filled" width="24" height="24" viewbox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> \
                                <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> \
                                <path d="M8.243 7.34l-6.38 .925l-.113 .023a1 1 0 0 0 -.44 1.684l4.622 4.499l-1.09 6.355l-.013 .11a1 1 0 0 0 1.464 .944l5.706 -3l5.693 3l.1 .046a1 1 0 0 0 1.352 -1.1l-1.091 -6.355l4.624 -4.5l.078 -.085a1 1 0 0 0 -.633 -1.62l-6.38 -.926l-2.852 -5.78a1 1 0 0 0 -1.794 0l-2.853 5.78z" stroke-width="0" fill="currentColor"></path> \
                                </svg>';
                that.empty();
                if (responseText.data.fav) {
                    favNum = favNum+1;
                    favicon = favicon+"<span id=\"favNum\">"+favNum+"</span>";
                    that.append(favicon);
                } else {
                    favNum = favNum>0?(favNum-1):0;
                    nofavicon = nofavicon+"<span id=\"favNum\">"+favNum+"</span>";
                    that.append(nofavicon);
                }
        }, 'json');
        return false;
    });
})(jQuery);
